import { getFolder } from "@/api/file";

export default {
  namespaced: true,
  state: {
    breadCrumbs: [],
    folderList: [],
    // 资源库面包屑
    resource: [],
    resourceList: [],
    recycleList:[],
  },
  mutations: {
    // pushBreadCrumpsFirst:(state,{id,name})=>{
    //   if (state.breadCrumbs.length === 1){
    //
    //   }
    // },
    /**
     * vuex点击插入面包屑
     * @param state
     * @param id
     * @param name
     */
    pushBreadCrumps: (state, { id, name }) => {
      state.breadCrumbs.push({ id: id, name: name });
      // console.log("push",state.breadCrumbs)
    },
    pushResource: (state, { id, name }) => {
      state.resource.push({ id: id, name: name });
    },
    deleteBreadCrumps: (state) => {
      Object.assign(state.breadCrumbs, []);
    },
    deleteResource: (state) => {
      state.resource = [];
    },
    /**
     * 插入文件集合
     */
    pushFolderList: (state, data) => {
      state.folderList.push(data);
    },
    pushResourceList: (state, data) => {
      state.resourceList.push(data);
    },
    pushRecycleList:(state, data) => {
      state.recycleList.push(data);
    },
    /**
     * 清空文件集合
     */
    deleteFolderList: (state, data) => {
      state.folderList = data;
    },
    deleteResourceList: (state, data) => {
      state.resourceList = [];
    },
    deleteRecycleList: (state,data) => {
      state.recycleList = [];
    },
    /**
     * 面包屑匹配
     */
    matchBreadCrumps: async (state, index) => {
      // console.log("前",state,index)
      // console.log(state.breadCrumbs.length - index -1)
      let len = state.breadCrumbs.length - index - 1;
      for (var i = 0; i < len; i++) {
        state.breadCrumbs.pop();
      }
      // console.log("后",state)
    },
    matchResource: async (state, index) => {
      console.log("前",state,index)
      let len = state.resource.length - index - 1;
      for (var i = 0; i < len; i++) {
        state.resource.pop();
      }
      console.log("后",state)
    },
  },

  /**
   *  获取头节点文件夹
   */
  action: {
    getFolderList() {
      getFolder(0).then((res) => {
        console.log("vuex : ", res);
      });
    },
  },
};
